*Structural-Analysis00.do
****************************************************************************************
**************************Analysis for 1999*********************************************
****************************************************************************************
 clear matrix

*
*log using "C:\Selfemployment\Self-Employment\selfemployment.smcl", replace
clear
set mem 300000
set matsize 800

set more off

*****************This Do-File Runs The Heckman Two-Step Selection Model*****************
*****************Note: Heckman Procedure Uses Reduced-Form Probit***********************

do  "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\Selection-Probit_00_df.do"

*****************This Files Run the CTaCS Program***************************************
*****************Note: WS = Wage/Salary SE = Self-Employment Real = Sample *************

do  "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\ctacsWS00.do"
do  "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\ctacsSE00.do"
do  "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\ctacsReal00.do"
do  "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\ctacsSED00.do"
do  "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\ctacsSEH00.do"


***************************Merge CTaCS Output to Master Data****************************


use "/Users/mdgordon/Desktop\Selfemployment\Ctacs\CTaCS-2008-1\inout\ctacs-00ws.dta", clear

rename id pucpid26 
rename totfedtax totfedtaxWS 
rename totprovtax totprovtaxWS 
rename tottax tottaxWS

keep pucpid26 totfedtaxWS totprovtaxWS tottaxWS

save "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\00ctacsWS.dta", replace

use "/Users/mdgordon/Desktop\Selfemployment\Ctacs\CTaCS-2008-1\inout\ctacs-00se.dta", clear

rename id pucpid26 
rename totfedtax totfedtaxSE 
rename totprovtax totprovtaxSE 
rename tottax tottaxSE

keep pucpid26 totfedtaxSE totprovtaxSE tottaxSE

save "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\00ctacsSE.dta", replace

use "/Users/mdgordon/Desktop\Selfemployment\Ctacs\CTaCS-2008-1\inout\ctacs-00real.dta", clear

rename id pucpid26 
rename totfedtax totfedtaxReal 
rename totprovtax totprovtaxReal
rename tottax tottaxReal

keep pucpid26 totfedtaxReal totprovtaxReal tottaxReal

save "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\00ctacsReal", replace

**********
use "/Users/mdgordon/Desktop\Selfemployment\Ctacs\CTaCS-2008-1\inout\ctacs-00SED.dta", clear
*** upside tax
rename id pucpid26 
rename totfedtax totfedtaxSED 
rename totprovtax totprovtaxSED 
rename tottax tottaxSED

keep pucpid26 totfedtaxSED totprovtaxSED tottaxSED

save "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\00ctacsSED.dta", replace

use "/Users/mdgordon/Desktop\Selfemployment\Ctacs\CTaCS-2008-1\inout\ctacs-00SEH.dta", clear
****downside tax
rename id pucpid26 
rename totfedtax totfedtaxSEH 
rename totprovtax totprovtaxSEH 
rename tottax tottaxSEH

keep pucpid26 totfedtaxSEH totprovtaxSEH tottaxSEH

save "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\00ctacsSEH.dta", replace
***********************
use "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\00analysis", clear

sort pucpid26
*drop _merge

merge using "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\00ctacsWS"
tab _merge
drop _merge

merge using "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\00ctacsSE"
tab _merge
drop _merge

merge using "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\00ctacsReal"
tab _merge
drop _merge
**********
merge using "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\00ctacsSED"
tab _merge
drop _merge
*
merge using "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\00ctacsSEH"
tab _merge
drop _merge
**************

*log using "C:\Selfemployment\Self-Employment\selfemployment.smcl", replace

**************Summarize Predicted Earnings and Predicted Taxes**********************

sum  btearningSE btearningE 
bysort selfemp:  sum earng42

sum  tottaxWS tottaxSE tottaxReal
bysort selfemp: sum inctx27 
sum inctx27 

sum  tottaxWS tottaxSE tottaxReal if inva27==0 & male==1
bysort selfemp: sum inctx27 if inva27==0 & male==1
sum inctx27 if inva27==0 & male==1


*
gen taxdif=  ((tottaxSE )/(tottaxWS))

gen Tax_ratio = (tottaxSE/(btearningSE+other-tottaxSE))
*drop if  Tax_ratio>1

gen taxU=(tottaxSED)/(tottaxSE)
gen taxdifU=  ln(taxU)*Tax_ratio
gen taxdifU2 = (taxU-1)*Tax_ratio

replace tottaxSEH=1 if tottaxSEH==0
gen taxD = (tottaxSEH)/(tottaxSE)
*gen taxD = (tottaxSE)/(tottaxSEH)
gen taxdifD = ln(taxD)*Tax_ratio
gen taxdifD2 = (taxD-1)*Tax_ratio


sum  tottaxSED tottaxSEH tottaxSE if tottaxSEH>0 & tottaxSE>0
drop if tottaxSEH<=0 | tottaxSE<=0  
sum  tottaxSED tottaxSEH tottaxSE  


* Keeping only variables to be used in final   model
keep date  other other2 rse Tax_ratio DhhE  inctx42 fditx42 pvitx42 inctx27 wkrcp42 spoucearn btearningE btearningSE  incomedif  year pucpid26 puchid25 selfemp inva27 inva42 capgn27   yrschl18 ecage26 age2 wksuem28 health male married   kids immigrant blucol   service newfoundland pei novascotia newbrunswick ontario quebec manitoba saskatchewan alberta bc earng42  wksuem28 udpd42 medx42 rppc42 rspwi42 pen42 oasgi42 cpqpp42 uiben42 capgn27 capgn42 sapis42 ottxm42 cpqpp42 alimo42 rppc42 chfed42 ccar42 alip42 year  kidage1-kidage7 rd yrxfte11  pctincearn whtcol incomedif  taxdif taxdifU taxdifU2 taxdifD taxdifD2 totfedtaxWS totprovtaxWS tottaxWS totfedtaxSE totprovtaxSE tottaxSE totfedtaxReal totprovtaxReal tottaxReal    
 
*SEstdf
*yrxfte11
 
 

save "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\00analysis", replace

 




  

